import Sact from "sact";

import {askJson,testUrl,format} from "./untils.js"
import file from "./file.js" 
let template = `
<div class="chatContent" :class="props.me ? 'chatRight' : 'chatLeft'">
<img s-if="!props.me" :src="userInfor[props.message.from].avatar_img_url" class="chatAvatar" style="margin-top:12px" >
<div class="chatContentRight" :style="{'align-items':props.me ? 'flex-end' : 'flex-start'}">
<div class="chatTagName" :style="{'margin-right':props.me ? '8px' : '0'}">
    {{userInfor[props.message.from].username}}
</div>
<div :class="props.me ? 'chatMyText' : 'chatTargetText'">
    <file :id="file.id" :title="file.title" :money="file.money / 100" :imgUrl="file.main_img_url" :time="file.c_time"></file>
    <div class="chatTagName" :class="props.me ? 'chatTimeLeftTag' : 'chatTimeRightTag'">{{props.message._time}}</div>
</div>
</div>
<img s-if="props.me" :src="userInfor[props.message.from].avatar_img_url" class="chatAvatar" alt="" style="margin-top:12px">
</div>
`
export default Sact.component({
    template,
    name: "filemessage",
    data(){
        return{
            file:{},
        }
    },
    props:["message","me"],
    component:{
        file,
    },
    mounted(){
        askJson(`${testUrl}/file/api/file/${this.props.message.hasfile.id}/`).then((d)=>{
            if(!d.detail){
                d.c_time = format(d.c_time,"yyyy-MM-dd");
                this.data.file = d;
            }
        })
    }
})